﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace MyUtility
{
    public struct FileInfoTypeDef 
    {
        public string Path;
        public long Size;
        public byte[] Content;
    };
    static public class MyFile
    {
      //  FileInfoTypeDef FileInfo;

        static public byte[] GetFileBinary(string filePath)
        {
            FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
            try
            {
                byte[] buffur = new byte[fs.Length];
                fs.Read(buffur, 0, (int)fs.Length);

                return buffur;
            }
            catch (Exception ex)
            {
                //MessageBoxHelper.ShowPrompt(ex.Message);
                return null;
            }
            finally
            {
                if (fs != null)
                {

                    //关闭资源
                    fs.Close();
                }
            }

        }

        public enum FileProcessType { 
            Error_Path,
            Error_Unknow,
            OK
        };
        static public FileProcessType GetFileBinary(ref FileInfoTypeDef _fileInfo)
        {
            if (_fileInfo.Path==string.Empty)
            {
                return FileProcessType.Error_Path;
            }
            FileStream fs = new FileStream(_fileInfo.Path, FileMode.Open, FileAccess.Read);
            try
            {
                byte[] buffur = new byte[fs.Length];
                fs.Read(buffur, 0, (int)fs.Length);
                _fileInfo.Content = buffur;
                _fileInfo.Size = fs.Length;
                return FileProcessType.OK;
            }
            catch (Exception ex)
            {
                //MessageBoxHelper.ShowPrompt(ex.Message);
                return FileProcessType.Error_Unknow;
            }
            finally
            {
                if (fs != null)
                {
                    //关闭资源
                    fs.Close();
                }
            }

        }
    }
}
